import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: () => import('../views/login/LoginView'),
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/AppHome'),
    children: [
      {
        //首页
        path: '/home',
        name: 'homes',
        meta: {
          isShow: true,
        },
        component: () => import('../views/home/HomeView.vue'),
      },
      {
        path: '/shade',
        name: 'shade',
        meta: {
          isShow: true,
        },
        component: () => import('../views/home/ShadeView.vue'),
      },
      {
        //权限列表
        path: '/home/pms',
        name: 'pms',
        component: () => import('../views/commodity/CommodityView'),
        children: [
          {
            path: '/home/pms/product',
            meta: {
              isShow: true,
            },
            component: () =>
              import('../views/commodity/components/ProductView'),
          },
          {
            path: '/home/pms/productCate',
            meta: {
              isShow: true,
            },
            component:()=>import("../views/commodity/components/ProductCateView")
          },{
            path:"/home/oms/order",
            meta:{
              isShow: true
            },
            component:()=>import("../views/order/components/OrderView")
          },{
            path:"/home/oms/brand",
            meta:{
              isShow: true
            },
            component:()=>import("../views/order/components/BrandView")
          },{
            path:"/home/oms/addgood",
            meta:{
              isShow: true
            },
            component:()=>import("../views/order/components/addGoodView")
          }
        ]
      },{
        //订单管理
        path:"/home/sms",
        name: "sms",
        component:()=>import("../views/masrketing/MasrketingView"),
        children:[
          {
            path:"/home/sms/visitor",
            meta:{
              isShow: true
            },
            component:()=>import("../views/masrketing/components/VisitorView")
          }
        ]
      },{
        //数据统计
        path:"/home/ums",
        name:"ums",
        component:()=>import("../views/jurisdiction/JurisdictinView"),
        children:[
          {
            path:"/home/ums/vueEdit",
            meta:{
              isShow: true
            },
            component:()=>import("../views/jurisdiction/components/VueEditView")
          }
        ]
      },,{
        path:"/home/user",
        name:"user",
        component:()=>import("../views/user/userView"),
        children:[
          {
            path:"/home/user/addProduct",
            meta:{
              isShow: true
            },
            component:()=>import("../views/user/components/AddProductView")
          }
        ]
      },
      {
        //商品管理
        path: '/home/oms',
        name: 'oms',
        component: () => import('../views/order/OrderView'),
        children: [
          {
            path: '/home/oms/orderSetting',
            meta: {
              isShow: true,
            },
            component: () =>
              import('../views/order/components/OrderSettingView'),
          },
          {
            path: '/home/oms/order',
            meta: {
              isShow: true,
            },
            component: () => import('../views/order/components/OrderView'),
          },
          {
            path: '/home/oms/brand',
            meta: {
              isShow: true,
            },
            component: () => import('../views/order/components/BrandView'),
          },
        ],
      },
      {
        //订单管理
        path: '/home/sms',
        name: 'sms',
        component: () => import('../views/masrketing/MasrketingView'),
        children: [
          {
            path: '/home/sms/visitor',
            meta: {
              isShow: true,
            },
            component: () =>
              import('../views/masrketing/components/VisitorView'),
          },
        ],
      },
      {
        //数据统计
        path: '/home/ums',
        name: 'ums',
        component: () => import('../views/jurisdiction/JurisdictinView'),
        children: [
          {
            path: '/home/ums/vueEdit',
            meta: {
              isShow: true,
            },
            component: () =>
              import('../views/jurisdiction/components/VueEditView'),
          },
        ],
      },
      {
        path: '/home/user',
        name: 'user',
        component: () => import('../views/user/userView'),
        children: [
          {
            path: '/home/user/addProduct',
            meta: {
              isShow: true,
            },
            component: () => import('../views/user/components/AddProductView'),
          },
        ],
      },
    ],
  },
]

const router = new VueRouter({
  routes,
})
// if (localStorage.getItem("token")) {
//   store.commit("setToken", localStorage.getItem("token"));
// }
router.beforeEach((to, from, next) => {
  if (to.meta && to.meta.isShow) {
    //获取token
    const user = localStorage.getItem('token')
    if (user) {
      next() //放行
    } else {
      next('/')
    }
  } else {
    next()
  }
})

export default router
